MODULE_NAME += gmsmx
TARGET=a.out

CURD := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
SRCS := $(shell cd $(CURD) && ls -f mpi/*.c 2>/dev/null | xargs)
SRCS += $(shell cd $(CURD) && ls -f sm2/*.c 2>/dev/null | xargs)
SRCS += $(shell cd $(CURD) && ls -f sm3/*.c 2>/dev/null | xargs)
SRCS += $(shell cd $(CURD) && ls -f sm4/*.c 2>/dev/null | xargs)
SRCS += $(shell cd $(CURD) && ls -f random/*.c 2>/dev/null | xargs)
OBJS := $(subst .c,.o,$(SRCS))

all: user kernel

clean:uclean kclean

# --- build user layer bin -- #
CC = gcc
TOP=$(shell pwd)
CFLAGE = -Wall -Werror -Wno-unused-but-set-variable -g -DDEBUG
INCLUDE_FLAGE = -I$(TOP)/inc

user:$(TARGET)

$(TARGET): $(OBJS) main_user.c
	$(CC) $^ -o $@  $(INCLUDE_FLAGE) $(CFLAGE)

%.o : %.c
	$(CC) -c $< -o $@ $(INCLUDE_FLAGE) $(CFLAGE)

uclean:
	rm -rf $(TARGET) $(OBJS)

# --- build kernel layer bin -- #

obj-m := $(MODULE_NAME).o
$(MODULE_NAME)-objs += main_kernel.o
$(MODULE_NAME)-objs += $(OBJS)

ccflags-y += -I$(src)/inc -DDEBUG
KDIR ?= /lib/modules/$(shell uname -r)/build

kernel:
	$(MAKE) -C $(KDIR) M=$$PWD

kclean:
	$(MAKE) -C $(KDIR) M=$$PWD clean
